package com.jt.tenant.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetProductQuery;
import com.jt.tenant.widget.Tools;

import java.util.List;


/**
 * Created by Administrator on 2016/2/16.
 */
public class MaintainShopAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;

    private List<GetProductQuery.NameList> list;

    private OnAddShopList addShopList;

    public MaintainShopAdapter(Context context, List<GetProductQuery.NameList> list,OnAddShopList addShopList) {

        layoutInflater = ((Activity) context).getLayoutInflater();

        this.list = list;

        this.addShopList = addShopList;

    }

    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = JTApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_maintain_shop, null));

            holder = new ViewHolder();

            holder.item_name = (TextView) convertView.findViewById(R.id.text_item_maintain_shop_name);

            holder.item_money = (TextView) convertView.findViewById(R.id.text_item_maintain_shop_money);

            holder.item_img = (ImageView) convertView.findViewById(R.id.img_item_maintain_shop);

            holder.img_add = (ImageView) convertView.findViewById(R.id.btn_item_maintain_shop_add);

            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }

        holder.item_name.setText(list.get(position).NAME);

        holder.item_money.setText("￥"+ Tools.F_num(list.get(position).PRICE));

        JTApplication.UtilAsyncBitmap.get(list.get(position).GOODS_IMG,holder.item_img);

        holder.img_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                addShopList.addShopList(list.get(position));

            }
        });

        return convertView;

    }

    private class ViewHolder {

        private TextView item_name;

        private TextView item_money;

        private ImageView item_img;

        private ImageView img_add;

    }

    public interface OnAddShopList{

        public void addShopList(GetProductQuery.NameList nameList);

    }

}
